package com.example.basic;

import com.example.basic.snowflake.DefaultIdGenerator;
import com.example.basic.snowflake.IdGenerator;

/**
 * 手动指定workerId
 */
public class SimpleIdGenerator implements SnowflakeIdGenerator {

    private final IdGenerator generator;

    /**
     * @param workerId 工作ID
     */
    public SimpleIdGenerator(int workerId) {
        this.generator = new DefaultIdGenerator(OFFSET_CLOCK, workerId, BITS_ALLOCATOR);
    }

    @Override
    public long generate() {
        return generator.getUID();
    }

    public String parseUID(long id) {
        return generator.parseUID(id);
    }
}
